﻿// Copyright (c) 2014 Converter Systems LLC

using ConverterSystems.Windows.Data;
using Opc.Ua;
using System;
using System.Globalization;
using System.Windows.Data;

namespace ConverterSystems.Workstation.Data
{
    [ValueConversion(typeof(VariantCollection), typeof(String))]
    public class BaseEventToStringConverter : ValueConverter<VariantCollection, String>
    {
        protected override String Convert(VariantCollection value, object parameter, CultureInfo culture)
        {
            //"EventId"
            //"EventType"
            //"SourceNode"
            //"SourceName"
            //"Time"
            //"ReceiveTime"
            //"LocalTime"
            //"Message"
            //"Severity"
            if (value == null || value.Count < 9)
            {
                return string.Empty;
            }
            var time = (DateTime)value[4].Value;
            return string.Format("{0:yyyy-MM-dd HH:mm:ss} {1}", time.ToLocalTime(), value[7].Value);
        }
    }
}